package com.logistics.utils.webservice.config;

import com.logistics.utils.configure.Configure;
import com.logistics.utils.webservice.service.IWebService;
import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.xml.ws.Endpoint;

@Configuration
@ConditionalOnProperty(name = {"configure.webService.gate"}, matchIfMissing = true)
public class WebServiceConfig {

    @Autowired
    private Configure configure;

    @Autowired
    private IWebService iWebService;

    @Bean(name = Bus.DEFAULT_BUS_ID)
    public SpringBus springBus(){
        return new SpringBus();
    }

    @Bean
    public Endpoint endpoint(){
        EndpointImpl endpoint = new EndpointImpl(springBus(), iWebService);
        endpoint.publish(configure.getWebService().getAddress());
        return endpoint;
    }

}
